{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# import necessary modules\n",
    "from classy import Class\n",
    "from math import pi"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#############################################\n",
    "#\n",
    "# Cosmological parameters and other CLASS parameters\n",
    "#\n",
    "common_settings = {# LambdaCDM parameters\n",
    "                   'h':0.67810,\n",
    "                   'omega_b':0.02238280,\n",
    "                   'omega_cdm':0.1201075,\n",
    "                   'A_s':2.100549e-09,\n",
    "                   'n_s':0.9660499,\n",
    "                   'tau_reio':0.05430842 ,\n",
    "                   # output and precision parameters\n",
    "                   'output':'tCl,pCl,lCl',\n",
    "                   'lensing':'yes',\n",
    "                   'l_max_scalars':5000}\n",
    "#\n",
    "M = Class()\n",
    "#\n",
    "###############\n",
    "#    \n",
    "# call CLASS for the total Cl's and then for each contribution\n",
    "#\n",
    "###############\n",
    "#\n",
    "M.set(common_settings)\n",
    "M.compute()\n",
    "cl_tot = M.raw_cl(3000)\n",
    "cl_lensed = M.lensed_cl(3000)\n",
    "M.empty()           # reset input\n",
    "#\n",
    "M.set(common_settings) # new input\n",
    "M.set({'temperature contributions':'tsw'}) \n",
    "M.compute()\n",
    "cl_tsw = M.raw_cl(3000) \n",
    "M.empty()\n",
    "#\n",
    "M.set(common_settings)\n",
    "M.set({'temperature contributions':'eisw'})\n",
    "M.compute()\n",
    "cl_eisw = M.raw_cl(3000) \n",
    "M.empty()\n",
    "#\n",
    "M.set(common_settings)\n",
    "M.set({'temperature contributions':'lisw'})\n",
    "M.compute()\n",
    "cl_lisw = M.raw_cl(3000) \n",
    "M.empty()\n",
    "#\n",
    "M.set(common_settings)\n",
    "M.set({'temperature contributions':'dop'})\n",
    "M.compute()\n",
    "cl_dop = M.raw_cl(3000) \n",
    "M.empty()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# modules and settings for the plot\n",
    "#\n",
    "# uncomment to get plots displayed in notebook\n",
    "%matplotlib inline\n",
    "import matplotlib\n",
    "import matplotlib.pyplot as plt\n",
    "# esthetic definitions for the plots\n",
    "font = {'size'   : 16, 'family':'STIXGeneral'}\n",
    "axislabelfontsize='large'\n",
    "matplotlib.rc('font', **font)\n",
    "matplotlib.mathtext.rcParams['legend.fontsize']='medium'\n",
    "plt.rcParams[\"figure.figsize\"] = [8.0,6.0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#################\n",
    "#\n",
    "# start plotting\n",
    "#\n",
    "#################\n",
    "#\n",
    "plt.xlim([2,3000])\n",
    "plt.xlabel(r\"$\\ell$\")\n",
    "plt.ylabel(r\"$\\ell (\\ell+1) C_l^{TT} / 2 \\pi \\,\\,\\, [\\times 10^{10}]$\")\n",
    "plt.grid()\n",
    "#\n",
    "ell = cl_tot['ell']\n",
    "factor = 1.e10*ell*(ell+1.)/2./pi\n",
    "plt.semilogx(ell,factor*cl_tsw['tt'],'c-',label=r'$\\mathrm{T+SW}$')\n",
    "plt.semilogx(ell,factor*cl_eisw['tt'],'r-',label=r'$\\mathrm{early-ISW}$')\n",
    "plt.semilogx(ell,factor*cl_lisw['tt'],'y-',label=r'$\\mathrm{late-ISW}$')\n",
    "plt.semilogx(ell,factor*cl_dop['tt'],'g-',label=r'$\\mathrm{Doppler}$')\n",
    "plt.semilogx(ell,factor*cl_tot['tt'],'r-',label=r'$\\mathrm{total}$')\n",
    "plt.semilogx(ell,factor*cl_lensed['tt'],'k-',label=r'$\\mathrm{lensed}$')\n",
    "#\n",
    "plt.legend(loc='right',bbox_to_anchor=(1.4, 0.5))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "plt.savefig('cltt_terms.pdf',bbox_inches='tight')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
